<template>
  <div class="boxs">
    <div class="left">
      <div
        v-for="(group, index) in groupedData"
        :key="index"
        class="month-group"
      >
    
        <h3>{{ group.month }}</h3>

        <div
          v-for="article in group.articles"
          :key="article.id"
          class="article-item"
        >
        
          <img :src="article.titleImage" alt="文章图片" class="article-img" />

          <div class="article-info">
            <p class="article-title">{{ article.title }}</p>
            <p class="article-time">{{ article.createTime }}</p>
          </div>
        </div>
      </div>
    </div>
    <div class="right">
      <Title-view></Title-view>
    </div>
  </div>
</template>

<script>
import TitleView from "../components/TitleView.vue";
export default {
  components: {
    TitleView,
  },
  data() {
    return {
      list: [], 
      groupedData: [],
      ruleForm: {
        current: 1,
        size: 10,
      },
    };
  },
  created() {
    this.getlist();
  },
  methods: {
    async getlist() {
      try {
        let res = await this.$axios.post("/api/index/article/list", this.ruleForm);
        console.log(res);
        
        this.list = res.data.data;
       
        this.groupedData = this.list;
      } catch (err) {
        console.error("获取数据失败：", err);
        this.list = [];
        this.groupedData = [];
      }
    },
  },
};
</script>

<style scoped>
.boxs {
  width: 100%;
  height: auto;
  margin: 0 auto;
  display: flex;
  justify-content: space-around;
}
.left {
  width: 70%;
  padding: 15px;
  background-color: #ffffff;
}
.right {
  width: 20%; 
}
.month-group {
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}
.month-group h3 {
  margin-top: 0;
  color: #333;
}
.article-item {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}
.article-img {
  width: 60px;
  height: 60px;
  border-radius: 4px;
  margin-right: 10px;
}
.article-info {
  flex: 1;
}
.article-title {
  margin: 0 0 5px 0;
  font-weight: bold;
}
.article-time {
  margin: 0;
  color: #666;
  font-size: 14px;
}
</style>